<!--#include file="../core/db.inc"-->
<!--#include file="../core/app.inc"-->
<!--#include file="../core/var.inc"-->
<!--#include file="../core/cache.inc"-->
<!--#include file="../core/json.inc"-->
<!--#include file="./inc/function.inc"-->
<!--#include file="../core/md5.inc"-->
<%
response.expiresAbsolute = now() - 1
response.expires = 0
response.cacheControl = "no-cache"
response.addHeader "pragma", "no-cache"
root = "../"
call db.open(root)
call app.webInit()
siteUrl = left(siteUrl, inStrRev(siteUrl, "/") - 1)
siteUrl = left(siteUrl, inStrRev(siteUrl, "/"))

dim aq
aq = lcase(trim(request("q")))

if aq = "login" then
	call checkLogin()
elseif aq = "out" then
	call adminOut()
else
	call index()
end if

call db.close()

function adminOut()
	app.setCookie "adminName", ""
	app.setCookie "password", ""
	response.write "<script>alert('退出成功');top.location.href='./index.asp';</script>"
end function

function index()
	dim str
	if app.isAdmin = false then
		%><!--#include file="./view/login.html"--><%
	else
		response.write "<script>alert('你已经登陆！');location.href='./index.asp';</script>"
	end if
end function

function checkLogin()
	'call app.checkPost()
	dim rs, str, i, iName, iPass, iCode, iKey, iTime
	iName = app.reChar(trim(request.form("adminName")))
	iPass = app.reChar(trim(request.form("password")))
	iCode = lcase(trim(request.form("checkCode")))
	if iCode = "" then
		app.json "2", "1" '请输入验证码
	end if
	if cstr(iCode) <> cstr(session(cacheName)) then
		app.json "3", "1" '验证码错误，请重新输入验证码
	end if
	if adminKey <> "" then
		iKey = app.reChar(trim(request.form("adminKey")))
		if iKey <> adminKey then
			app.json "1", "1" '后台管理认证码不对，请重新输入 adminKey
		end if
	end if
	if iName = "" then
		app.json "4", "1" '请输入名称
	end if
	if iPass = "" then
		app.json "5", "1" '请输入密码
	end if
	iPass = getMd5(iPass)
	set rs = db.exec("select id,adminName,nickName,password,loginIP,loginTime,loginNumber,loginInfo from cj_admin where adminName='" & iName & "' and password='" & iPass & "'", 3)
	if rs.bof and rs.eof then
		session(cacheName) = ""
		app.json "6", 1 '名称或密码错误
	end if
	iTime = now()
	rs(4) = userIP
	rs(5) = iTime
	rs(6) = rs(6) + 1
	rs(7) = rs(6) & "次：" & iTime & "，IP：" & userIP & chr(13) & rs(7)
	rs.update
	for i = 0 to rs.Fields.count - 2
		adminInfo(i) = rs(i)
	next
	rs.close : set rs = nothing
	app.setCookie "adminName", adminInfo(1)
	app.setCookie "password", adminInfo(3)
	session(cacheName) = ""
	app.json "0", "0" '登陆成功
end function

%>